<?php
/**
 * @author tungck
 * @filesource sukien_model.php
 * file model for process position manager
*/
?>

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class event_model extends CI_Model{
    
    public $tableName = 'sukien';
    
    function __construct(){
        parent::__construct();
        $this->load->helper('url');
        $this->load->database();
        
    }
    
    // lay danh sách vi tri chuc danh
    function getList($data){
        $recordCount = $this->db->count_all_results('sukien');
        $query = $this->db->query("SELECT * FROM sukien ORDER BY " . $data['sort'] . " LIMIT " . $data['startIndex'] . "," . $data['pageSize'] . ";");
        if($query){
            $result['query'] = $query->result();
            $result['recordCount'] = $recordCount;
            return $result;
        }else{
            return false;
        }
        
    }
    
    function getDetailList($id){
        $query = $this->db->query("SELECT * FROM sukien WHERE MaSuKien = ".$id);
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function getAll(){
        $query = $this->db->query("SELECT * FROM sukien");
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function getById($id){
        $query = $this->db->query("SELECT TenBoPhan FROM sukien WHERE MaBoPhan = ".$id);
        if($query){
            return $query->result();
        }else{
            return false;
        }
        
    }
    
    function saveEvent($data){
        $this->db->insert('sukien', $data);
        //$query = $this->db->get_where('sukien', 'MaBoPhan = LAST_INSERT_ID()');
        if($query){
            return $query->result();
        }else{
            return false;
        }
    }
    
    function deleteEvent($id){
        $this->db->delete('sukien', array('MaSuKien'=>$id));
    }
    
    function updateEvent($data){
        $this->db->where('MaSuKien', $data['MaSuKien']);
        $this->db->update('sukien', $data); 
    }
    
}

?>